{extend name="base/base" /}
{block name="style"}
<style type="text/css">

</style>
{/block}
{block name="content"}
<div class="layui-form-item layui-form-pane">
      <div class="layui-inline">
          <div class="demoTable">
            <button class="layui-btn layui-btn-normal" onclick="add()">新增</button>
          </div>
        </div>
        <table id="table" lay-filter="table"></table> 

</div>
<script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script type="text/html" id="barDemo1">
  <a class="layui-btn layui-btn-xs" lay-event="show">查看</a>
  <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
</script>

{/block}
{block name="script"}
<script>
layui.use('table', function(){
  var table = layui.table; 
  table.render({
  elem: '#table'
  ,height: 'full-150'
  ,url: '/admin/notice/dataList/' //数据接口
  ,limit:20
  ,page: true //开启分页
  ,cols: [[ //表头
    {field:'date', title: '发布时间', width: 200}
    ,{field:'title', title: '标题', width:500}
    ,{title:'内容', toolbar: '#barDemo1', width:200}
    ,{title:'操作', toolbar: '#barDemo', width:200}
    ]]
  }); 
  //监听工具条
  table.on('tool(table)', function(obj){
    var data = obj.data;
    if(obj.event === 'del'){
      layer.confirm('确定删除？', function(index){
        $.ajax({
          url:"{:url('admin/notice/del')}?id="+data.id,
          type:'GET',
          success:function(ret){
            if(ret.code == 0) {
              layer.msg('删除成功');
              obj.del();
            } else {
              layer.msg('删除失败');
            }
          }
        });
      });
    } else if(obj.event === 'edit'){
      layer.open({
        type: 2 ,
        title: '编辑配置',   //标题
        area: ['800px', '500px'],   //宽高
        shade: 0.4,   //遮罩透明度
        content: '/admin/notice/editNotice?id='+data.id,//支持获取DOM元素
        // end:function(){
        //   $(".layui-laypage-btn")[0].click();
        // }
        });
    }else if(obj.event === 'show'){
      layer.open({
        type: 1,
        skin: 'layui-layer-rim', //加上边框
        area: ['400px', '600px'], //宽高
        content: data.content
      });
    } 
  });
});
function add(){
  layer.open({
        type: 2 ,
        title: '编辑配置',   //标题
        area: ['800px', '500px'],   //宽高
        shade: 0.4,   //遮罩透明度
        content: '/admin/notice/editNotice',//支持获取DOM元素
        // end:function(){
        //   $(".layui-laypage-btn")[0].click();
        // }
        });
}
</script>
{/block}
